'''
排班管理相关接口测试
'''
from Lib.base.keywords import KeyWords
from selenium.webdriver.common.by import By
from Lib.common.common_function import *
from Lib.base.page_object.login_page import LonginPage


class DutyManagerList(KeyWords):
    url = KeyWords.url + 'schedule-management/list'

    # -------------排班列表---------------------
    # 按排班时间进行筛选
    filter_by_time_seven = (By.XPATH, '//span[text()="近7天"]')
    filter_by_time_fifteen = (By.XPATH, '//span[text()="近15天"]')
    filter_by_time_default = (By.XPATH, '//span[text()="不限"]')
    # 姓名进行搜索
    duty_search_input = (By.XPATH, '//input[@placeholder="请输入姓名"]')
    duty_search_button = (By.XPATH, '//i[contains(@class, "rz-icon-search")]')

    def duty_list(self):
        '''
        排班列表查询相关操作
        :return:
        '''
        self.open(url=self.url)
        self.wait(2)
        # 按时间进行筛选
        self.click(args=self.filter_by_time_seven, context="近7天")
        self.wait(1)
        self.click(args=self.filter_by_time_fifteen, context="近15天")
        self.wait(1)
        self.click(args=self.filter_by_time_default, context="不限")
        self.wait(1)
        # 根据姓名进行搜索排班
        self.input_value(args=self.duty_search_input, text="申请人kb", context="姓名搜索框")
        self.click(args=self.duty_search_button, context="搜索")
        self.wait(1)
        self.clear_input(args=self.duty_search_input, context="姓名搜索框")
        self.input_value(args=self.duty_search_input, text="申请人kbAAA", context="姓名搜索框")
        self.click(args=self.duty_search_button, context="搜索")
        self.wait(1)

    def duty_list_update(self):
        '''
        查询和修改排班
        :param data:
        :return:
        '''
        data = get_data_by_yaml(get_path() + r'\Data\element_data\duty\duty_update.yaml')
        element_operation(self, data[0]['data'])

    def duty_list_delete(self):
        '''
        查询和修改排班
        :param data:
        :return:
        '''
        data = get_data_by_yaml(get_path() + r'\Data\element_data\duty\duty_delete.yaml')
        element_operation(self, data[0]['data'])


if __name__ == '__main__':
    driver = choose_browser()
    L = LonginPage(driver)
    L.login('kobeAdmin002', 'kobe8888')
    case = DutyManagerList(driver)
    case.duty_list_delete()
